package cn.sciento.mybatis.helper;

public class TenantDbLimitHelper {
    private static final ThreadLocal<TenantDbLimitHelper.TenantDbLimited> TENANT_LIMITED_REQUEST = new ThreadLocal<>();

    public static void setTenantId(Long tenantId){
        if(TENANT_LIMITED_REQUEST.get() != null){
            TENANT_LIMITED_REQUEST.get().setTenantId(tenantId);
        }else {
            TENANT_LIMITED_REQUEST.set(new TenantDbLimitHelper.TenantDbLimited(tenantId));
        }
    }

    public static Long getTenantId(){
        if(TENANT_LIMITED_REQUEST.get() != null){
            return TENANT_LIMITED_REQUEST.get().getTenantId();
        }else {
            return null;
        }
    }


    public static class TenantDbLimited{

        public TenantDbLimited(Long tenantId) {
            this.tenantId = tenantId;
        }

        private Long tenantId;

        public Long getTenantId() {
            return tenantId;
        }

        public void setTenantId(Long tenantId) {
            this.tenantId = tenantId;
        }
    }
}
